import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router';
import { useToolStore } from '@renderer/store';
// let ToolStore = useToolStore();




// 引入自定义的组件

import homeIndex from '@renderer/pages/home/index.vue';
import serverIndex from '@renderer/pages/server/index.vue';
import frpIndex from '@renderer/pages/frp/index.vue';
import settingIndex from '@renderer/pages/setting/index.vue';


// 服务器的子页面

import serverConsole from '@renderer/pages/server/console.vue';




// 1. 定义路由组件：这里直接用的对象数据，也可以导入其他组件。
// const Main = { render() { return '我是交互型应用哦！' } };

const routes = [
    {
        path: '/',
        redirect: '/home/index' // 将根路径重定向到 '/home'
    },
    // 主页面
    {
        path: '/home/index',
        component: homeIndex,
        name:'home',
        meta: {
            keepAlive: true
        }
    },
    {
        path: '/server/index',
        component: serverIndex,
        name:'server',
        meta: {
            keepAlive: true
        }
    },
    {
        path: '/frp/index',
        component: frpIndex,
        name:'frp',
        meta: {
            keepAlive: true
        }
    },
    {
        path: '/setting/index',
        component: settingIndex,
        name:'setting',
        meta: {
            keepAlive: true
        }
    },
    // 其它页面


    // 主页的子页面

    // 服务器的子页面

    // 控制台
    {
        path: '/server/console',
        component: serverConsole,
        name:'console',
        meta: {
            keepAlive: false
        }
    },
    // frp的子页面

    // 设置的子页面
];

const router = createRouter({
    // history: createWebHistory(),
    history: createWebHashHistory(),
    routes,
});

// afterEach 导航守卫
router.afterEach((to, from) => {
    let toolStore = useToolStore();
    toolStore.navigationMenu.forEach(item => {
        let se = new RegExp(`^${item.activate}.*`);
        if (se.test(to.path)) {
            item.isActivate = true;
        } else {
            item.isActivate = false;
        }
    });
});

export default router;